package com.supermap.dataservice.common.dao;

import com.supermap.dubbo.api.common.entity.Yield;
import org.apache.ibatis.annotations.*;

import java.time.Year;
import java.util.List;

/**
 * @Author:langhongshuai
 * @Description:产量数据访问层
 * @Date:18/8/22 下午2:57
 */
@Mapper
public interface YieldDao {

    /**
     * 向数据库增加产量信息
     * @param yield
     */
    @Insert("Insert into t_yield(yield,crop,time) values(#{yield.yield},#{yield.crop},#{yield.time})")
    public void addYieldInfo(@Param("yield") Yield yield);

    /**
     * 向数据库更新产量信息
     * @param yield
     */
    @Update("Update t_yield set yield=#{yield.yield} where id=#{yield.id}")
    public void updateYieldsInfo(@Param("yield")Yield yield);

    /**
     * 通过作物和年份获取作物该年份的以后的产量信息
     * @param crop
     * @param time
     * @return
     */
    @Select("Select * from t_yield where crop =#{crop} and time >=#{time} order by time desc")
    public List<Yield> getYieldsInfoByCropAndTime(@Param("crop") String crop, @Param("time") int time);

    /**
     * 检查该年份的作物产量是否已经存在
     * @param yield
     * @return
     */
    @Select("Select * from t_yield where crop=#{yield.crop} and time=#{yield.time}")
    public List<Yield> checkFieldExits(@Param("yield")Yield yield);
}
